FROM alpine:3.8

RUN echo "http://mirrors.ustc.edu.cn/alpine/v3.8/main/" > /etc/apk/repositories && \
     echo "http://mirrors.ustc.edu.cn/alpine/v3.8/community/" >> /etc/apk/repositories

RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

ENV GOLANG_VERSION 1.10.3.linux-amd64

RUN set -eux; \
	apk add --no-cache \
		bash \
		musl-dev \
		go \
	; \
	wget -O go.tgz "https://studygolang.com/dl/golang/go$GOLANG_VERSION.tar.gz"; \
	tar -C /usr/local -xzf go.tgz; \
	rm go.tgz; \
	\
	export PATH="/usr/local/go/bin:$PATH"; \
	go version

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH